home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gekikoh Dennoh Club 5
/
Gekikoh Dennoh Club Vol. 5 (Japan).7z
/
Gekikoh Dennoh Club Vol. 5 (Japan) (Track 01).bin
/
internet
/
tcppack
/
tcppackb.lzh
/
src
/
libether
/
libether.c
Wrap
C/C++ Source or Header
|
1995-11-07
|
9KB
|
419 lines
/*
* libether.a - C library for Etherdrv API.
*
* Copyright (C) 1994 First Class Technology.
*/
#include<stddef.h>
#include<string.h>
#include"etherdrv.h"
#include<stddef.h>
#include<string.h>
#define __DOS_INLINE__
#include<sys/dos.h>
#include"etherdrv.h"
#define DEV_NAME_LEN (8)
#define MAX_DEVICE (8)
typedef struct dev_link
{
struct dev_link *next;
unsigned short attribute;
void *str;
void *intr;
unsigned char dev_name[DEV_NAME_LEN];
} dev_link;
typedef struct dev_stat
{
unsigned char name[DEV_NAME_LEN];
int trap_no;
etd_func func;
} dev_stat;
static dev_stat func[MAX_DEVICE];
static int search_etd_entry (char *);
static etd_func search_etd_entry_sub (char *);
static long _etd_entry (etd_cmd, void *, int);
static long _etd_entry2 (etd_cmd, void *, int);
/************************************************
* *
************************************************/
long
ETDGetDriverVersion (char *dev_name, int *ino)
{
*ino = search_etd_entry (dev_name);
if (*ino < 0)
return *ino;
return _etd_entry (etd_get_driver_version, NULL, *ino);
}
/************************************************
* *
************************************************/
eaddr *
ETDGetMacAddr (eaddr *dst, int ino)
{
return (eaddr *)_etd_entry (etd_get_mac_addr, dst, ino);
}
/************************************************
* *
************************************************/
eaddr *
ETDGetPromAddr (eaddr *dst, int ino)
{
return (eaddr *)_etd_entry (etd_get_prom_addr, dst, ino);
}
/************************************************
* *
************************************************/
int
ETDSetMacAddr (eaddr *dst, int ino)
{
return _etd_entry (etd_set_mac_addr, dst, ino);
}
/************************************************
* *
************************************************/
int
ETDSendPacket (int size, void *packet, int ino)
{
long args[2];
args[0] = size;
args[1] = (long)packet;
return _etd_entry (etd_send_ether_packet, args, ino);
}
/************************************************
* *
************************************************/
int
ETDSetIntAddr (unsigned long prt, void *_func, int ino)
{
long args[2];
args[0] = prt;
args[1] = (long)_func;
return _etd_entry (etd_set_int_addr, args, ino);
}
/************************************************
* *
************************************************/
void *
ETDGetIntAddr (unsigned long prt, int ino)
{
return (void *)_etd_entry (etd_get_int_addr, (long*)prt, ino);
}
/************************************************
* *
************************************************/
int
ETDDelIntAddr (unsigned long prt, int ino)
{
return _etd_entry (etd_del_int_addr, (long *)prt, ino);
}
/************************************************
* *
************************************************/
int
ETDSetMulticastAddr (char *p, int ino)
{
return _etd_entry (etd_set_multicast_addr, (long *)p, ino);
}
/************************************************
* *
************************************************/
int
ETDGetStatistics (char *p, int ino)
{
return _etd_entry (etd_get_statistics, (long *)p, ino);
}
/************************************************
* *
************************************************/
static int
search_etd_entry (char *dev_name)
{
long ssp;
etd_func _func;
int i;
_func = NULL;
for (i = 0; i < MAX_DEVICE; i++)
{
if (*func[i].name && !memcmp (func[i].name, dev_name, DEV_NAME_LEN))
{
_func = func[i].func;
break;
}
else if (!func[i].func)
break;
}
if (!_func)
{
/* Did I find any space to store? */
if (i < MAX_DEVICE)
{
ssp = _dos_super (0);
_func = search_etd_entry_sub (dev_name);
if (ssp > 0)
_dos_super (ssp);
if (_func)
{
memcpy (func[i].name, dev_name, DEV_NAME_LEN);
func[i].func = _func;
func[i].trap_no = -1;
func[i].trap_no = _etd_entry (-1, NULL, i);
return i;
}
else
return -1;
}
else
return -1;
}
else
return i;
}
/************************************************
* *
************************************************/
static etd_func
search_etd_entry_sub (char *dev_name)
{
unsigned short *p;
int found;
dev_link *cur;
/* search NUL */
found = 0;
for (p = (unsigned short *)0x6800; p < (unsigned short *)0x68000; p++)
{
if (*p == 'NU' && *(p + 1) == 'L ' && *(p + 2) == ' ' && *(p + 3) == ' ')
{
found = 1;
break;
}
}
if (!found)
return NULL;
/* device link é≡ ÆHéΘ */
found = 0;
cur = (dev_link *)((char *)p - offsetof (dev_link, dev_name));
for (; cur != (dev_link *)0xffffffff; cur = cur->next)
{
if (!memcmp (cur->dev_name, dev_name, DEV_NAME_LEN)
&& !memcmp ((char *)cur + sizeof (dev_link), "EthD", 4))
{
found = 1;
break;
}
}
if (!found)
return NULL;
return (etd_func)((char *)cur + sizeof (dev_link) + 8);
}
/************************************************
* *
************************************************/
static long
_etd_entry (etd_cmd cmd, void *args, int ino)
{
register long result asm ("d0");
register etd_func _func asm ("a1");
int i;
if ((i = func[ino].trap_no) >= 0)
return _etd_entry2 (cmd, args, i);
_func = func[ino].func;
asm volatile ("move.l\t%2,a0\n"
"\tmove.l\t%1,d0\n"
"\tmove.l\t%3,-(sp)\n"
"\tDOS\tSUPER_JSR\n"
"\taddq.l\t#4,sp"
: "d=" (result)
: "g" (cmd), "g" (args), "g" (_func)
: "d0", "a0");
return result;
}
/*
**
*/
static long
trap_0 (etd_cmd cmd, void *arg)
{
register long result asm ("d0");
asm volatile ("move.l\t%2,a0\n"
"\tmove.l\t%1,d0\n"
"\ttrap\t#0\n"
: "d=" (result)
: "g" (cmd), "g" (arg)
: "d0", "d1", "d2", "a0", "a1", "a2");
return result;
}
/*
**
*/
static long
trap_1 (etd_cmd cmd, void *arg)
{
register long result asm ("d0");
asm volatile ("move.l\t%2,a0\n"
"\tmove.l\t%1,d0\n"
"\ttrap\t#1\n"
: "d=" (result)
: "g" (cmd), "g" (arg)
: "d0", "d1", "d2", "a0", "a1", "a2");
return result;
}
/*
**
*/
static long
trap_2 (etd_cmd cmd, void *arg)
{
register long result asm ("d0");
asm volatile ("move.l\t%2,a0\n"
"\tmove.l\t%1,d0\n"
"\ttrap\t#2\n"
: "d=" (result)
: "g" (cmd), "g" (arg)
: "d0", "d1", "d2", "a0", "a1", "a2");
return result;
}
/*
**
*/
static long
trap_3 (etd_cmd cmd, void *arg)
{
register long result asm ("d0");
asm volatile ("move.l\t%2,a0\n"
"\tmove.l\t%1,d0\n"
"\ttrap\t#3\n"
: "d=" (result)
: "g" (cmd), "g" (arg)
: "d0", "d1", "d2", "a0", "a1", "a2");
return result;
}
/*
**
*/
static long
trap_4 (etd_cmd cmd, void *arg)
{
register long result asm ("d0");
asm volatile ("move.l\t%2,a0\n"
"\tmove.l\t%1,d0\n"
"\ttrap\t#4\n"
: "d=" (result)
: "g" (cmd), "g" (arg)
: "d0", "d1", "d2", "a0", "a1", "a2");
return result;
}
/*
**
*/
static long
trap_5 (etd_cmd cmd, void *arg)
{
register long result asm ("d0");
asm volatile ("move.l\t%2,a0\n"
"\tmove.l\t%1,d0\n"
"\ttrap\t#5\n"
: "d=" (result)
: "g" (cmd), "g" (arg)
: "d0", "d1", "d2", "a0", "a1", "a2");
return result;
}
/*
**
*/
static long
trap_6 (etd_cmd cmd, void *arg)
{
register long result asm ("d0");
asm volatile ("move.l\t%2,a0\n"
"\tmove.l\t%1,d0\n"
"\ttrap\t#6\n"
: "d=" (result)
: "g" (cmd), "g" (arg)
: "d0", "d1", "d2", "a0", "a1", "a2");
return result;
}
/*
**
*/
static long
trap_7 (etd_cmd cmd, void *arg)
{
register long result asm ("d0");
asm volatile ("move.l\t%2,a0\n"
"\tmove.l\t%1,d0\n"
"\ttrap\t#7\n"
: "d=" (result)
: "g" (cmd), "g" (arg)
: "d0", "d1", "d2", "a0", "a1", "a2");
return result;
}
static long (*trap_entry[8]) (etd_cmd, void *) =
{
trap_0, trap_1, trap_2, trap_3,
trap_4, trap_5, trap_6, trap_7,
};
/************************************************
* *
************************************************/
static long
_etd_entry2 (etd_cmd cmd, void *args, int i)
{
if (i < 0 || i > 7)
return -1;
return trap_entry[i] (cmd, args);
}